package com.vcc.web.core.interceptor;

import cn.dev33.satoken.stp.StpInterface;
import com.vcc.core.util.RedisCustomizeUtils;
import com.vcc.data.mapper.ClientPermissionMapper;
import com.vcc.service.service.ClientPermissionService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.concurrent.TimeUnit;

@Component
public class StpInterfaceImpl implements StpInterface {

    @Resource
    private ClientPermissionService clientPermissionService;


    @Override
    public List<String> getPermissionList(Object o, String s) {
        String key = "user_client_permission:" + o.toString();
        if (RedisCustomizeUtils.hasKey(key)) {
            return RedisCustomizeUtils.getList(key, String.class);
        } else {
            List<String> list = clientPermissionService.listByUserId(Long.valueOf(o.toString()));
            if (list != null && !list.isEmpty()) {
                RedisCustomizeUtils.set(key, list, 5L, TimeUnit.MINUTES);
            }
            return list;
        }
    }

    @Override
    public List<String> getRoleList(Object o, String s) {
        return List.of();
    }
}
